package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.RestBean;
import com.hs.entity.dto.PriceRule;
import com.hs.entity.dto.Team;
import com.hs.service.PriceRuleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/priceRule")
public class PriceRuleController {
    @Resource
    private PriceRuleService priceRuleService;

    @GetMapping("/getPriceRuleList/{currentNum}")
    public RestBean<PageInfo<PriceRule>> getPriceRuleList(
            @PathVariable("currentNum") Integer currentNum,
            @RequestParam(required = false) String keywords) {
        PageInfo<PriceRule> priceRuleList = priceRuleService.selectPriceRuleList(currentNum,keywords);
        return RestBean.success(priceRuleList);
    }

    @GetMapping("/getAllPriceRuleList")
    public RestBean<List<PriceRule>> getAllPriceRuleList() {

        List<PriceRule> list = priceRuleService.list();
        return RestBean.success(list);
    }

    @PostMapping("/updatePriceRule")
    public RestBean<PriceRule> updatePriceRule( @RequestBody PriceRule priceRule) {
        System.out.println(priceRule);
        priceRuleService.updateById(priceRule);
        return RestBean.success(null);
    }

    @PostMapping("/addPriceRule")
    public RestBean<PriceRule> addPriceRule( @RequestBody PriceRule priceRule) {
        priceRule.setCreateTime(LocalDateTime.now());
        priceRuleService.save(priceRule);
        return RestBean.success(null);
    }

    @PostMapping("/deletePriceRule/{id}")
    public RestBean<PriceRule> deletePriceRule(@PathVariable  Integer id) {
        priceRuleService.removeById(id);
        return RestBean.success(null);
    }
}
